package com.xinzhidi.web.netty.controller;

import com.xinzhidi.common.annotation.Log;
import com.xinzhidi.common.core.controller.BaseController;
import com.xinzhidi.common.core.domain.AjaxResult;
import com.xinzhidi.common.core.domain.R;
import com.xinzhidi.common.core.page.TableDataInfo;
import com.xinzhidi.common.enums.BusinessType;
import com.xinzhidi.common.utils.poi.ExcelUtil;
import com.xinzhidi.web.netty.entity.dto.AgreementHouseholdValveHistoryAddDto;
import com.xinzhidi.web.netty.entity.dto.AgreementHouseholdValveHistoryListDto;
import com.xinzhidi.web.netty.entity.dto.AgreementHouseholdValveHistoryUpdDto;
import com.xinzhidi.web.netty.entity.vo.AgreementHouseholdValveHistoryInfoVo;
import com.xinzhidi.web.netty.entity.vo.AgreementHouseholdValveHistoryListVo;
import com.xinzhidi.web.netty.service.AgreementHouseholdValveHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * 户用阀门协议-历史数据Controller
 *
 * @author cx
 * @date 2023-06-16
 */
@RestController
@Api(tags = "户用阀门协议-历史数据")
@RequestMapping("/householdValveHistory")
public class AgreementHouseholdValveHistoryController extends BaseController {
    @Autowired
    private AgreementHouseholdValveHistoryService agreementHouseholdValveHistoryService;

    @ApiOperation("查询户用阀门协议-历史数据列表")
    @PreAuthorize("@ss.hasPermi('householdValveHistory:householdValveHistory:list')")
    @PostMapping("/listAgreementHouseholdValveHistory")
    public TableDataInfo<AgreementHouseholdValveHistoryListVo> listAgreementHouseholdValveHistory(@Validated @RequestBody AgreementHouseholdValveHistoryListDto dto) {
        startPagePost(dto);
        return agreementHouseholdValveHistoryService.selectAgreementHouseholdValveHistoryList(dto);
    }

    @ApiOperation("导出户用阀门协议-历史数据列表")
    @PreAuthorize("@ss.hasPermi('householdValveHistory:householdValveHistory:export')")
    @Log(title = "户用阀门协议-历史数据", businessType = BusinessType.EXPORT)
    @PostMapping("/exportAgreementHouseholdValveHistory")
    public void exportAgreementHouseholdValveHistory(HttpServletResponse response, AgreementHouseholdValveHistoryListDto dto) {
        TableDataInfo<AgreementHouseholdValveHistoryListVo> list = agreementHouseholdValveHistoryService.selectAgreementHouseholdValveHistoryList(dto);
        ExcelUtil<AgreementHouseholdValveHistoryListVo> util = new ExcelUtil<AgreementHouseholdValveHistoryListVo>(AgreementHouseholdValveHistoryListVo.class);
        util.exportExcel(response, list.getRows(), "户用阀门协议-历史数据数据");
    }

    @ApiOperation("获取户用阀门协议-历史数据详细信息")
    @PreAuthorize("@ss.hasPermi('householdValveHistory:householdValveHistory:query')")
    @GetMapping(value = "/getAgreementHouseholdValveHistoryById")
    public R<AgreementHouseholdValveHistoryInfoVo> getAgreementHouseholdValveHistoryById(@RequestParam("id") Long id) {
        return R.ok(agreementHouseholdValveHistoryService.selectAgreementHouseholdValveHistoryById(id));
    }

    @ApiOperation("新增户用阀门协议-历史数据")
    @PreAuthorize("@ss.hasPermi('householdValveHistory:householdValveHistory:add')")
    @Log(title = "户用阀门协议-历史数据", businessType = BusinessType.INSERT)
    @PostMapping("addAgreementHouseholdValveHistory")
    public AjaxResult addAgreementHouseholdValveHistory(@Validated @RequestBody AgreementHouseholdValveHistoryAddDto dto) {
        return toAjax(agreementHouseholdValveHistoryService.insertAgreementHouseholdValveHistory(dto));
    }

    @ApiOperation("修改户用阀门协议-历史数据")
    @PreAuthorize("@ss.hasPermi('householdValveHistory:householdValveHistory:edit')")
    @Log(title = "户用阀门协议-历史数据", businessType = BusinessType.UPDATE)
    @PostMapping("editAgreementHouseholdValveHistory")
    public AjaxResult editAgreementHouseholdValveHistory(@Validated @RequestBody AgreementHouseholdValveHistoryUpdDto dto) {
        return toAjax(agreementHouseholdValveHistoryService.updateAgreementHouseholdValveHistory(dto));
    }

    @ApiOperation("删除户用阀门协议-历史数据")
    @PreAuthorize("@ss.hasPermi('householdValveHistory:householdValveHistory:remove')")
    @Log(title = "户用阀门协议-历史数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/delAgreementHouseholdValveHistory")
    public AjaxResult delAgreementHouseholdValveHistory(@RequestParam Long[] ids) {
        return toAjax(agreementHouseholdValveHistoryService.deleteAgreementHouseholdValveHistoryByIds(ids));
    }
}
